package MediaEntity;

public class musicThread extends Thread{
    private musicStream musicStream;
    //两种构造musicstream的方式
    public musicThread(String filePath){
        this.musicStream=new musicStream(filePath);
    }
    public musicThread(musicStream t){
        this.musicStream=t;
    }

    public void switchSong(String filePath){
        this.musicStream.getPlayer().close();
        this.musicStream=new musicStream(filePath);
        this.start();
    }
    @Override
    public void run() {

        musicStream.play();
    }
    /*
     * 丑陋的暂停
     */
    public void pause(){
        this.suspend();
    }
    public synchronized void restart(){
            this.resume();
    }
    public void close(){
        musicStream.close();
    }
    /*
     * 切换到歌曲指定帧数开始播放
     * @param i 是帧数，以整数的形式传入
     */
    public void switchFrame(int i){
        musicStream.getPlayer().stop();
        musicStream.regainPlayer();
        musicStream.play(i);
    }



}
